//
//  AXMyNzjyztVC.m
//  AnXin100
//
//  Created by 天质弘耕 on 2018/11/8.
//  Copyright © 2018 tzhg. All rights reserved.
//
/** 农资经营主体 */
#import "AXMyNzjyztVC.h"
#import "ZXCategories.h"
#import "UIView+SDAutoLayout.h"
#import "AXMyNewFarmerNameCell.h"
#import "AXMyNewFarmerSexCell.h"
#import "AXMyNewFarmerPictureCell.h"
#import "AXMyNewFarmerSubmitCell.h"
#import "TZHGMyViewController.h"
#import "AXMyButtonSelectCell.h"
#import "AXMyTitleCell.h"
#import "AXMyAddressSelectCell.h"
#import "AXMyCheckProgressVC.h"

@interface AXMyNzjyztVC ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic , strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *array;

@end

@implementation AXMyNzjyztVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    [self creatView];
    [self setlayout];
    [self setupNavigationItems];
    
    _array = @[@"民营", @"国企", @"央企", @"事业单位"];
    
}


- (void)creatView {
    
    self.tableView = [[UITableView alloc]init];
    /** 去掉cell线 */
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    /** tableView滚动收键盘 */
    self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerClass:[AXMyNewFarmerNameCell class] forCellReuseIdentifier:[AXMyNewFarmerNameCell reuseID]];
    [self.tableView registerClass:[AXMyNewFarmerSexCell class] forCellReuseIdentifier:[AXMyNewFarmerSexCell reuseID]];
    [self.tableView registerClass:[AXMyNewFarmerPictureCell class] forCellReuseIdentifier:[AXMyNewFarmerPictureCell reuseID]];
    [self.tableView registerClass:[AXMyNewFarmerSubmitCell class] forCellReuseIdentifier:[AXMyNewFarmerSubmitCell reuseID]];
    [self.tableView registerClass:[AXMyButtonSelectCell class] forCellReuseIdentifier:[AXMyButtonSelectCell reuseID]];
    [self.tableView registerClass:[AXMyTitleCell class] forCellReuseIdentifier:[AXMyTitleCell reuseID]];
    [self.tableView registerClass:[AXMyAddressSelectCell class] forCellReuseIdentifier:[AXMyAddressSelectCell reuseID]];
    
    [self.view addSubview:self.tableView];
}


- (void)setlayout {
    
    self.tableView.sd_layout
    .leftSpaceToView(self.view, 0)
    .topSpaceToView(self.view, NAVIGATION_HEIGHT)
    .widthIs(Wi)
    .heightIs(TableViewHeight);
    
    
}


- (void)setupNavigationItems {
    
    /** 导航条左边的按钮 */
    //返回按钮
    UIButton *kfBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [kfBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    kfBtn.frame = CGRectMake(0, 0, 30, 30);
    [kfBtn addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:kfBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
    /** 搜索 */
    UILabel *titleLabel = [[UILabel alloc]init];
    titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
    titleLabel.text = @"农业经营主体";
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.font = FONT_EIGHTEEN;
    titleLabel.textColor = [UIColor colorWithHex:0x29b566];
    self.navigationItem.titleView = titleLabel;
    
    
}

#pragma mark - Action

- (void)backAction:(UIBarButtonItem *)item {
    [self.navigationController popViewControllerAnimated:YES];
}



#pragma mark - tableviewDlegate & tableviewDelegate

//几个分区
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 14;
}

/** cell的高度 */

/** cell 自适应第二步 */
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    if (indexPath.row == 11||indexPath.row == 12) {
        
        return 150;
        
    }
    
    if (indexPath.row == 10) {
        
        return 200;
    }
    
    else if (indexPath.row == 10){
        
        return 200;
    }
    
    
    //按钮的高度
    else if (indexPath.row == 3){
        
        if (_array.count % 4 == 0) {
            return (_array.count / 4) * 35 + 10;
        } else {
            return (_array.count / 4 + 1) * 35 + 10;
        }
    }
    return 44;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    
    //判断选择
    if (indexPath.row == 1||indexPath.row == 5) {
        
        AXMyAddressSelectCell *farmerSexCell = [tableView dequeueReusableCellWithIdentifier:[ AXMyAddressSelectCell reuseID] forIndexPath:indexPath];
        [farmerSexCell setSelectionStyle:UITableViewCellSelectionStyleNone];
        
        if (indexPath.row == 1) {
            
            [farmerSexCell.addressBtn setTitle:@"云南省 昆明市 盘龙区" forState:UIControlStateNormal];
            farmerSexCell.titleLabel.text = @"家庭住址";
            farmerSexCell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            
        }
        
        else if (indexPath.row == 5) {
            
            
            
            [farmerSexCell.addressBtn setTitle:@"云南省 昆明市 盘龙区" forState:UIControlStateNormal];
            farmerSexCell.titleLabel.text = @"经营范围";
            farmerSexCell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            
        }
        
        
        return farmerSexCell;
    }
    // 判断单位性质选择按钮
    else if (indexPath.row == 4) {
        
        AXMyButtonSelectCell *buttonSelectCell = [tableView dequeueReusableCellWithIdentifier:[AXMyButtonSelectCell reuseID] forIndexPath:indexPath];
        buttonSelectCell.array = _array;
        [buttonSelectCell setSelectionStyle:UITableViewCellSelectionStyleNone];
        return buttonSelectCell;
    }
    
    else if (indexPath.row == 3) {
        
        AXMyTitleCell *titleCell = [tableView dequeueReusableCellWithIdentifier:[AXMyTitleCell reuseID] forIndexPath:indexPath];
        [titleCell setSelectionStyle:UITableViewCellSelectionStyleNone];
        titleCell.titleLabel.text = @"单位性质";
        return titleCell;
        
    }
    
    
    
    /** 判断是输入 */
    else  if (indexPath.row == 0||indexPath.row ==2||indexPath.row ==6||indexPath.row ==8||indexPath.row ==9) {
        
        AXMyNewFarmerNameCell *nameCell = [tableView dequeueReusableCellWithIdentifier:[AXMyNewFarmerNameCell reuseID] forIndexPath:indexPath];
        [nameCell setSelectionStyle:UITableViewCellSelectionStyleNone];
        
        if (indexPath.row == 0) {
            
            nameCell.nameLabel.text = @"姓名";
            
        }
        else if (indexPath.row == 2) {
            
            nameCell.nameLabel.text = @"详情地址";
            nameCell.inputTextField.placeholder = @"点击填写详细地址";
            
        }
        
        else if (indexPath.row == 6) {
            
            nameCell.nameLabel.text = @"法定代表人姓名";
            
        }
        else if (indexPath.row == 8) {
            
            nameCell.nameLabel.text = @"法定代表人手机号";
        }
        
        else if (indexPath.row == 9) {
            
            nameCell.nameLabel.text = @"身份证号";
        }
        
        
        return nameCell;
    }
    
    //判断是上传照片
    else if (indexPath.row == 10||indexPath.row == 11||indexPath.row == 12) {
        
        AXMyNewFarmerPictureCell *pictureCell = [tableView dequeueReusableCellWithIdentifier:[AXMyNewFarmerPictureCell reuseID] forIndexPath:indexPath];
        [pictureCell setSelectionStyle:UITableViewCellSelectionStyleNone];
        
        if (indexPath.row == 10) {
            
            pictureCell.sfzLabel.text= @"身份证照片";
            pictureCell.frontLabel.text = @"正面";
            pictureCell.reverseSideLabel.text = @"反面";
            
            
        }
        else if (indexPath.row == 11) {
            
            pictureCell.sfzLabel.text= @"营业执照";
            pictureCell.reverseSideBtn.hidden = YES;
            [pictureCell.selectBtn setTitle:@"有效期 >" forState:UIControlStateNormal];
            
        }
        
        else if (indexPath.row == 12) {
            
            pictureCell.sfzLabel.text= @"银行开户许可证";
            pictureCell.reverseSideBtn.hidden = YES;
        }
        

        
        return  pictureCell;
        
    }
    
    
    else if (indexPath.row == 13) {
        
        //提交
        
        AXMyNewFarmerSubmitCell *submitCell = [tableView dequeueReusableCellWithIdentifier:[ AXMyNewFarmerSubmitCell reuseID] forIndexPath:indexPath];
        [submitCell setSelectionStyle:UITableViewCellSelectionStyleNone];
        [submitCell setSelectionStyle:UITableViewCellSelectionStyleNone];
        submitCell.saveBtn.hidden = YES;
        submitCell.saveBtn.cornerRadius =5;
        submitCell.SelectBtn.hidden = NO;
        submitCell.agreeLabel.hidden = NO;
        submitCell.submiBtn.hidden = NO;
        submitCell.agreeLabel.text = @"同意入驻协议";
        [submitCell.submiBtn setTitle:@"确认提交" forState:UIControlStateNormal];
        submitCell.tapButtonClickedBlock = ^(NSInteger index) {
            
            AXMyCheckProgressVC *vc = [[AXMyCheckProgressVC alloc] initWithNibName:@"AXMyCheckProgressVC" bundle:[NSBundle mainBundle]];
            [self.navigationController pushViewController:vc animated:YES];
            
        };
        
        
        return submitCell;
        
    }
    
    AXMyNewFarmerSexCell *farmerSexCell = [tableView dequeueReusableCellWithIdentifier:[AXMyNewFarmerSexCell reuseID] forIndexPath:indexPath];
    [farmerSexCell setSelectionStyle:UITableViewCellSelectionStyleNone];
    
    farmerSexCell.sexLabel.text = @"性别";
    farmerSexCell.womanLabel.text = @"女";
    farmerSexCell.manLabel.text = @"男";
    
    return farmerSexCell;
    
    
    
}



@end
